<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>学生注册</title>
    <link href="bootstrap-4.6.1-dist/css/bootstrap.min.css"
          type="text/css" rel="stylesheet">
    <link rel="stylesheet" href="css/StudentRed.css">
    <style type="text/css">
        #main{
            padding-top: 50px;
        }
        .btn{
            width: 120px;
            height: 50px;
            margin: 10px;
        }
    </style>
</head>
<body>

<div id="main">


    <form id="stuForm">
        <div class="form-group row">
            <label class="col-form-label col-2 text-center"></label>
            <div class="col-8">
                <input type="text" name="loginName" class="form-control"placeholder="请输入账号">
            </div>
        </div>
        <div class="form-group row">
            <label class="col-form-label col-2 text-center"></label>
            <div class="col-8">
                <input type="password" name="loginPwd" class="form-control"placeholder="请输入密码">
            </div>
        </div>
        <div class="form-group row">
            <label class="col-form-label col-2 text-center"></label>
            <div class="col-8">
                <input type="text" class="form-control" name="stuName"placeholder="真实姓名">
            </div>
        </div>
        <div class="form-group row">
            <label class="col-form-label col-2 text-center"></label>
            <div class="col-8">
                <input type="text" class="form-control" name="stuEmail"
                       placeholder="邮箱信息">
            </div>
        </div>
        <div class="form-group row">
            <label class="col-form-label col-2 text-center"></label>
            <div class="col-8">
                <button type="button" id="btnReg" class="btn btn-lg btn-success">注册</button>
                <button type="reset"  id="btnLogin"class="btn btn-lg btn-danger">重置</button>
            </div>
        </div>
    </form>

</div>
</body>
<script src="jquery/jquery-3.6.0.min.js"></script>
<script>
    jQuery(function () {
        //给按钮添加事件
        jQuery("#btnReg").click(function () {
            //获取表单中数据
            //控件必须有name属性
            let form=jQuery("#stuForm").serialize();
            console.log(form);
            //使用Ajax
            // let flag=0;
            jQuery.post("student/segsearch",form,function (rst1) {
                console.log(rst1.length);
                if(rst1.length!=0){
                    alert("账号重复");
                }else {
                        jQuery.post("student/reg",form,function (rst2) {
                            if(rst2){
                                alert("注册成功");
                                location.href='StudentLogin.html';
                                sessionStorage.setItem("seg_form",form);
                            }
                        })
                }
            });
        })
    });
</script>
<script src="bootstrap-4.6.1-dist/js/bootstrap.min.js"></script>


</html>